package com.dnui.seven2.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnui.seven2.common.R;
import com.dnui.seven2.entity.Employee;
import com.dnui.seven2.entity.Merch;
import com.dnui.seven2.entity.Shows;
import com.dnui.seven2.service.ShowsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/shows")
@Slf4j
public class ShowsController {
    @Autowired
    private ShowsService showsService;

    @GetMapping("/queryShows")
    public R<Page> queryShows(@PathVariable Integer currentPageNum, @PathVariable Integer everyPage ){
        //构造分页构造器
        Page pageInfo=new Page(currentPageNum,everyPage);
        //构造条件构造器
        LambdaQueryWrapper<Shows> queryWrapper=new LambdaQueryWrapper();

        //执行查询
        showsService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }

    @PostMapping("/saveShow")
    public R<String> saveShow(@RequestBody Shows show){
        showsService.save(show);
        return  R.success("添加成功");
    }

    @DeleteMapping("/deleteShow/{showId}")
    public R<String> deleteShow(@PathVariable Long showId){
        showsService.deleteShow(showId);
        return  R.success("删除成功");
    }

    @PutMapping("/updateShow")
    public R<String> updateShow(@RequestBody Shows show){
        showsService.updateShow(show);
        return  R.success("修改成功");
    }

    @GetMapping("/getById/{showId}")
    public R<Shows> getById(@PathVariable Long showId){
        log.info("根据id查询员工信息");
        Shows show=showsService.getById(showId);
        return R.success(show);
    }

    @GetMapping("/selectAll")
    public R<List<Shows>> selectAll(){
        List<Shows> shows = showsService.selectAll();
        return  R.success(shows);
    }
}
